package edu.hawaii.ics111.exam;

/**
 * The supplementary materials for a question or group of questions.
 * This may consist of code, selections from an API, or whatever else is deemed necessary.
 * ExamViewer may then place this in a separate window (or pane, depending on implementation)
 * for the user to view.
 * 
 * @author Branden Ogata
 *
 */

public class ExamSupplement extends ExamItem
{
  /**
   * The title of the supplement.
   * 
   */
  private String title;
  
  /**
   * The supplementary information necessary to answer the problem.
   * 
   */
  private String supplement;
  
  /**
   * Initializes the supplementary information for a question or group of questions.
   * 
   * @param title A String containing a descriptor for the supplementary materials.
   * @param supplement A String containing the supplementary materials.
   * 
   */
  
  public ExamSupplement(String title, String supplement)
  {
    this.title = title;
    this.supplement = supplement;
  }

  /**
   * Returns the title of this ExamSupplement.
   *
   * @return title The String containing the title of this ExamSupplement.
   *
   */
  
  public String getTitle()
  {
    return this.title;
  }

  /**
   * Sets the title of this ExamSupplement.
   *
   * @param title The String containing the title to set for this ExamSupplement.
   *
   */
  
  public void setTitle(String title)
  {
    this.title = title;
  }

  /**
   * Returns the supplement of this ExamSupplement.
   *
   * @return supplement The String containing the supplement of this ExamSupplement.
   *
   */
  
  public String getSupplement()
  {
    return this.supplement;
  }

  /**
   * Sets the supplement of this ExamSupplement.
   *
   * @param supplement The String containing the supplement to set for this ExamSupplement.
   *
   */
  
  public void setSupplement(String supplement)
  {
    this.supplement = supplement;
  }
  
  /**
   * Returns the height of this ExamSupplement.
   * This is equivalent to the number of lines in the supplement.
   * 
   * @return height An int equal to the number of lines in the supplement.
   * 
   */
  
  public int getHeight()
  {
    int height = 1;
    char[] characters = this.supplement.toCharArray();
    
    for (char c : characters)
    {
      if (c == '\n')
      {
        height++;
      }
    }
    
    return height;
  }
  
  /**
   * Returns the width of this ExamSupplement.
   * This is equivalent to the number of characters in the largest line of the supplement.
   * 
   * @return width An int equal to the greatest number of characters in a line of the supplement.
   * 
   */
  
  public int getWidth()
  {
    int width = 1; 
    
    String[] lines = this.supplement.split("\n");
    
    for (String s : lines)
    {
      if (s.length() > width)
      {
        width = s.length();
      }
    }
    
    return width;
  }
}
